;装载到位于MBR的引导程序
;用于计算1+2+3+...+100的结果，并输出到屏幕上

jmp near start

formula db '1+2+3+...+100='

start:
    mov ax,0x07c0
    mov ds,ax

    mov ax,0xb800
    mov es,ax

    ;显示算式
    mov si,formula
    mov di,0
    mov cx,start-formula
@a:
    mov al,[si]
    mov [es:di],al
    inc di
    mov byte [es:di],0x07
    inc di
    inc si
    loop @a

    ;计算加和
    xor ax,ax
    mov cx,1
@b:
    add ax,cx
    add cx,1
    cmp cx,100
    jle @b

    ;初始化ss
    xor cx,cx
    mov ss,cx
    mov sp,cx
    ;拆分各位，放入ss
    mov bx,10
    xor cx,cx
@c:
    xor dx,dx
    div bx
    or dl,0x30
    push dx
    inc cx
    cmp al,0
    jne @c

    ;拿出显示各位
@d:
    pop dx
    mov [es:di],dx
    inc di
    mov byte [es:di],0x04
    inc di
    loop @d

    jmp near $ 
       

times 510-($-$$) db 0
                 db 0x55,0xaa

